CMAKE_MINIMUM_REQUIRED(VERSION 2.8) # cmake最低版本要求

PROJECT(CppServer)    # 工程名 CppServer

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread") # 添加c++11标准支持

SET(CMAKE_C_COMPILER "/usr/bin/gcc") # 默认c编译器
SET(CMAKE_CXX_COMPILER "/usr/bin/g++") # 默认c++编译器
set(CMAKE_CXX_STANDARD_REQUIRED True)

SET(CMAKE_BUILD_TYPE "Debug")  # Debug模式 选项: Release Debug MinSizeRel RelWithDebInfo

SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")  # debug模式下 gdb相关选项
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") # release模式下 gdb相关选项

# set(CMAKE_VERBOSE_MAKEFILE ON) # 开启调试 出现问题时开启

# enable_testing() # 打开测试

add_definitions(-DDEBUG) # 相当于代码中 #define DEBUG

# add_library()

# add_subdirectory(test) # 添加test子目录

MESSAGE("Finding packages...")
# include_directories(/usr/include/jsoncpp/json)
# include_directories(/usr/include/hiredis)
# include_directories(/usr/include/spdlog)
set(INC_DIR /usr/local/include)  
set(LINK_DIR /usr/local/lib)
set(LLHTTPPATH /home/tanlin/llhttp)


SET(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/bin") # 可执行文件输出目录

INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/include") # 头文件包含目录
include_directories(${INC_DIR})
include_directories(${LLHTTPPATH})
link_directories(${LINK_DIR})

# 这段代码可以区分操作系统
MESSAGE("Identifying the OS...")
if(WIN32)
  MESSAGE("This is Windows.")
elseif(APPLE)
  MESSAGE("This is MacOS.")
elseif(UNIX)
  MESSAGE("This is Linux.")
endif()
# 这段代码可以区分操作系统

AUX_SOURCE_DIRECTORY(src DIR_SRCS) # 添加源代码文件夹, 自动扫描所有文件


add_executable(
    theServer  # 输出名为xx执行文件
    ${DIR_SRCS}
)

target_link_libraries(theServer jsoncpp hiredis spdlog)
target_link_libraries(theServer llhttp)
# target_link_libraries(theServer /usr/lib/x86_64-linux-gnu/libjsoncpp.so)
# target_link_libraries(theServer /usr/lib/x86_64-linux-gnu/libhiredis.so.0.14)
# target_link_libraries(theServer /usr/lib/x86_64-linux-gnu/libspdlog.so.1.5.0)

# 也可以这么写
# add_executable(chess  # 输出名为chess的可执行文件
#    ./src/main.cpp
#    ./src/utils.cpp
# )